package org.hackystat.projectbrowser.page.setaction;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import org.hackystat.ambientdevice.device.bunny.Nabaztag.EarPosition;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Animation;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Color;
import org.hackystat.ambientdevice.server.jaxb.Action;

/**
 * Model for the Action
 * 
 * @author Sonwright M. Gomez
 * 
 */
public class ActionModel implements Serializable {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  Action action;
  String deviceName;
  String actionType;
  String value;
  Color[] arrayOfColors;
  Animation[] arrayOfAnimations;
  EarPosition[] arrayOfEarPos;
  static final List<Color> listOfColors = new ArrayList<Color>();
  static final List<Animation> listOfAnimations = new ArrayList<Animation>();
  static final List<EarPosition> listOfEarPos = new ArrayList<EarPosition>();

  /**
   * ActionModel constructor. Might want to change how to get list of everything later. For now,
   * this is the only thing I can think of because my brain is dead ZOMG!!!!
   * 
   * @param action The action to be constructed.
   */
  public ActionModel(org.hackystat.ambientdevice.server.jaxb.Action action) {
    this.action = action;
    arrayOfColors = Color.values();
    arrayOfAnimations = Animation.values();
    arrayOfEarPos = EarPosition.values();
    for (Color color : arrayOfColors) {
      listOfColors.add(color);
    }
    for (Animation animation : arrayOfAnimations) {
      listOfAnimations.add(animation);
    }

    for (EarPosition earPos : arrayOfEarPos) {
      listOfEarPos.add(earPos);
    }
  }

  /**
   * The getter for the Animation.
   * 
   * @return The animation.
   */
  public List<Animation> getAnimation() {
    return ActionModel.listOfAnimations;
  }

  /**
   * The getter for the ear position.
   * 
   * @return List of eat positions.
   */
  public List<EarPosition> getEarPosition() {
    return ActionModel.listOfEarPos;
  }

  /**
   * The getter for the color.
   * 
   * @return The color.
   */
  public List<Color> getColors() {
    return ActionModel.listOfColors;
  }

  /**
   * The setter for the device name.
   * 
   * @param string The device name.
   */
  public void setActionDeviceName(String string) {
    this.deviceName = string;
  }

  /**
   * The getter for the device name.
   * 
   * @return The device name.
   */
  public String getActionDeviceName() {
    return this.deviceName;
  }

  /**
   * The setter for the action type.
   * 
   * @param string The action type.
   */
  public void setActionActionType(String string) {
    this.actionType = string;
  }

  /**
   * The getter for th ActionType.
   * 
   * @return The action Type.
   */
  public String getActionActionType() {
    return this.actionType;
  }

  /**
   * The setter for the ActionValue.
   * 
   * @param string The value.
   */
  public void setActionValue(String string) {
    this.value = string;
  }

  /**
   * The getter for the ActionValue.
   * 
   * @return returns the value.
   */
  public String getActionValue() {
    return this.value;
  }

  /**
   * Get the choices available for the action form.
   * 
   * @param type The type of action.
   * @return The list of choices for the action.
   */
  protected static ArrayList<String> getChoices(String type) {
    ArrayList<String> list = new ArrayList<String>();
    if ("deviceName".equals(type)) {
      list.add("Orb");
      list.add("Bunny");
    }
    else if ("actionType".equals(type)) {
      System.out.println("actionType equals type");
      list.add("ChangeAnimation");
      list.add("ChangeColor");
      list.add("MoveLeftEarPosition");
      list.add("MoveRightEarPosition");
      list.add("TTS");
    }
    else if ("valueModel".equals(type)) {
      list.add("BUILD SUCCESSFUL");
      list.add("BUILD FAIL");
      list.add("UNIT TEST FAIL");
      list.add("COVERAGE DROPPING");
      list.add("ZERO");
      list.add("FIVE");
      list.add("TEN");
      list.add("SIXTEEN");
    }
    else if ("Orb".equals(type)) {
      list.add("ChangeColor");
      list.add("ChangeAnimation");
    }
    else if ("Bunny".equals(type)) {
      list.add("MoveLeftEarPosition");
      list.add("MoveRightEarPosition");
      list.add("TTS");
    }
    else if ("ChangeColor".equals(type)) {
      for (Color color : listOfColors) {
        if (!(color.toString().equalsIgnoreCase("unsupported"))) {
          list.add(color.toString());

        }
      }
      Collections.sort(list);
    }
    else if ("ChangeAnimation".equals(type)) {
      for (Animation animation : listOfAnimations) {
        if (!(animation.toString().equalsIgnoreCase("unsupported"))) {
          list.add(animation.toString());
        }
      }
    }
    else if ("MoveLeftEarPosition".equals(type) || "MoveRightEarPosition".equals(type)) {
      for (EarPosition pos : listOfEarPos) {
        list.add(pos.toString());
      }
    }
    else if ("TTS".equals(type)) {
      list.add("BUILD SUCCESSFUL");
      list.add("BUILD FAILURE");
      list.add("UNIT TEST FAILURE");
      list.add("COVERAGE DROPPING BELOW");
    }

    return list;
  }
}
